import 'package:flutter/material.dart';
import 'package:flutter_chat_ui/views/chat_bottom_widgets/mask_content_widgets/bottom_oval_view.dart';
import 'package:flutter_chat_ui/views/chat_bottom_widgets/mask_content_widgets/speech_to_text_view.dart';
import 'package:flutter_chat_ui/views/chat_bottom_widgets/mask_content_widgets/wave_view.dart';
import 'package:flutter_chat_ui/views/chat_bottom_widgets/voice_controller.dart';
import 'package:get/get.dart';

///
/// 语音识别蒙版视图
///
class SpeechMaskView extends StatefulWidget {
  const SpeechMaskView({
    super.key,
  });

  @override
  State<SpeechMaskView> createState() => _SpeechMaskViewState();
}

class _SpeechMaskViewState extends State<SpeechMaskView> {
  @override
  void initState() {
    Get.put(VoiceController());
    super.initState();
  }

  @override
  void dispose() {
    Get.delete<VoiceController>();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Material(
      color: Colors.black.withValues(alpha: 0.5),
      child: Stack(
        alignment: Alignment.bottomCenter,
        children: [
          Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              Expanded(
                child: Container(
                  margin: const EdgeInsets.only(top: 80),
                  child: const Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      /// 顶部录制语音波浪动画 - 完全独立的动画
                      WaveView(),

                      /// 语音转文本，显示文本
                      Padding(
                        padding: EdgeInsets.only(top: 20),
                        child: SpeechToTextView(),
                      ),
                    ],
                  ),
                ),
              ),

              /// 底部圆弧
              const BottomOvalView(),
            ],
          ),
        ],
      ),
    );
  }
}
